#include "head.h"
char *generate_random_string(int length) {
    char *random_str = (char *)malloc(length + 1);
    static const char alphanum[] =
        "0123456789"
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        "abcdefghijklmnopqrstuvwxyz";

    if (random_str == NULL) {
        fprintf(stderr, "Memory allocation failed.\n");
        exit(1);
    }

    // 初始化随机数种子
    srand((unsigned int) time(NULL));

    for (int i = 0; i < length; ++i) {
        random_str[i] = alphanum[rand() % (sizeof(alphanum) - 1)];
    }

    random_str[length] = '\0';

    return random_str;
}


